import {
  INIT_STATE,
  USER_LOGIN,
  USER_LOGOUT,
  EXERCISE_ADD,
  EXERCISE_INIT,
  EXERCISE_EMPTY
} from './mutation-types'

import {
  setStore,
  getStore,
  removeStore
} from '../util/util';


const matutaions = {
  [INIT_STATE](state) {
    let inituserlogin = getStore('userlogin'),
    exerciseInfo=getStore('exerciseInfo')
    if (inituserlogin) {
      state.userlogin = inituserlogin;
    }
		if(exerciseInfo){
			state.exerciseInfo=exerciseInfo
		}
  },
  [USER_LOGIN](state, userlogin) {
    state.userlogin = userlogin;
    setStore('userlogin', state.userlogin);
  },

  [USER_LOGOUT](state) {
    state.userlogin = null;
    removeStore('userlogin')
  },
  [EXERCISE_ADD](state,info){
  	state.exerciseInfo=info;
  	setStore('exerciseInfo',state.exerciseInfo);
  },
  [EXERCISE_EMPTY](state){
  	state.exerciseInfo=null
  	removeStore('exerciseInfo')
  }

}

export default matutaions
